package org.ala.tiktools.rpc.config;

import org.ala.tiktools.rpc.client_server.service.IRpcServiceReceiver;
import org.ala.tiktools.rpc.plugin.load_balance.ILoadBalance;
import org.ala.tiktools.rpc.plugin.load_balance.selector.ISelector;
import org.ala.tiktools.rpc.plugin.node.INodeCreator;
import org.ala.tiktools.rpc.plugin.serializer.ISerializer;

/**
 * rpc相关配置
 *
 * @author ala
 * @date 2025-04-05 22:10
 */
public class RpcConfigInfo {
    /**
     *  配置项
     */
    public static RpcConfigInfo INSTANCE;


    /**
     *  LoadBalance类型
     *  <p> 默认全局只有1个LoadBalance对象
     *  <p> 如果某个Client配的是私有链接，或自己指定了LoadBalance，则会给这个bean配自己的LoadBalance对象
     */
    protected Class<? extends ILoadBalance> loadBalanceClass;
    /**
     *  节点构建器
     */
    @SuppressWarnings("rawtypes")
	protected Class<? extends INodeCreator> nodeCreatorClass;
    /**
     *  节点选择器
     */
    protected Class<? extends ISelector> nodeSelectorClass;
    /**
     *  消息接收器
     */
    protected Class<? extends IRpcServiceReceiver> serviceReceiverClass;
    /**
     * 	序列化反序列化类型
     */
    protected Class<? extends ISerializer> serializeClass;
    /**
     * 	序列化默认消息大小
     */
    protected int serializeDefSize = 4096;
    /**
     * 	序列化/反序列化线程数
     */
    protected int serializePoolSize = -1;
    /**
     * 	序列化/反序列化是否原地执行
     */
    protected boolean serializeInPlace = false;
    /**
     * AlaRpcClient注解的包目录
     */
    protected String[] rpcClientPackages;
    /**
     *  刷节点信息间隔
     */
    protected long reNodeInfoInterval = 60000;
    /**
     *  节点重连间隔
     *  <p> 每次重连间隔会增加reActiveInterval
     */
    protected long reActiveInterval = 5000;
    /**
     *  最大重连间隔
     *  <p> 每次重连间隔会增加reActiveInterval，这里是增加的最大值
     *  <p> 只要节点存在就会一直重连，除非把节点摘掉
     */
    protected long reActiveMaxInterval = 120000;
    /**
     *  从注册中心拉取节点信息时间间隔
     */
    protected long rePopNodeInterval = 60000;
    /**
     *  网络请求超时时间
     *  <p> 默认6秒
     */
    protected long timeout = 6000;
    /**
     *  心跳间隔
     */
    protected long idleInterval = 6000;
    /**
     *  心跳超时关闭次数
     */
    protected int idleTimesClose = 5;
    /**
     * rpc服务端执行任务线程池coreSize
     * <p>  这里是公共线程池，允许Bean持有私有线程池
     */
    protected int serviceCoreSize = 20;
    /**
     *  rpc服务端执行任务线程池maxSize
     */
    protected int serviceMaxSize = 20;
    /**
     *  rpc服务端执行任务线程池队列长度
     */
    protected int serviceQueueSize = 1024;
    /**
     * 	默认的发送端拦截器链
     */
    protected String[] interceptorSenderChain;
    /**
     * 	默认的接收端拦截器链
     */
    protected String[] interceptorReceiverChain;
    /**
     *  身份认证相关配置
     */
    protected RpcAuth auth;


    public Class<? extends ILoadBalance> getLoadBalanceClass() {
        return loadBalanceClass;
    }

    public void setLoadBalanceClass(Class<? extends ILoadBalance> loadBalanceClass) {
        this.loadBalanceClass = loadBalanceClass;
    }

    public long getReActiveInterval() {
        return reActiveInterval;
    }

    public void setReActiveInterval(long reActiveInterval) {
        this.reActiveInterval = reActiveInterval;
    }

    public long getReActiveMaxInterval() {
        return reActiveMaxInterval;
    }

    public void setReActiveMaxInterval(long reActiveMaxInterval) {
        this.reActiveMaxInterval = reActiveMaxInterval;
    }

    public long getTimeout() {
        return timeout;
    }

    public void setTimeout(long timeout) {
        this.timeout = timeout;
    }

    public int getServiceCoreSize() {
        return serviceCoreSize;
    }

    public void setServiceCoreSize(int serviceCoreSize) {
        this.serviceCoreSize = serviceCoreSize;
    }

    public int getServiceMaxSize() {
        return serviceMaxSize;
    }

    public void setServiceMaxSize(int serviceMaxSize) {
        this.serviceMaxSize = serviceMaxSize;
    }

    public int getServiceQueueSize() {
        return serviceQueueSize;
    }

    public void setServiceQueueSize(int serviceQueueSize) {
        this.serviceQueueSize = serviceQueueSize;
    }

    @SuppressWarnings("rawtypes")
	public Class<? extends INodeCreator> getNodeCreatorClass() {
        return nodeCreatorClass;
    }

    @SuppressWarnings("rawtypes")
	public void setNodeCreatorClass(Class<? extends INodeCreator> nodeCreatorClass) {
        this.nodeCreatorClass = nodeCreatorClass;
    }

    public long getRePopNodeInterval() {
        return rePopNodeInterval;
    }

    public void setRePopNodeInterval(long rePopNodeInterval) {
        this.rePopNodeInterval = rePopNodeInterval;
    }

    public Class<? extends ISelector> getNodeSelectorClass() {
        return nodeSelectorClass;
    }

    public void setNodeSelectorClass(Class<? extends ISelector> nodeSelectorClass) {
        this.nodeSelectorClass = nodeSelectorClass;
    }

    public RpcAuth getAuth() {
        return auth;
    }

    public void setAuth(RpcAuth auth) {
        this.auth = auth;
    }

    public Class<? extends IRpcServiceReceiver> getServiceReceiverClass() {
        return serviceReceiverClass;
    }

    public void setServiceReceiverClass(Class<? extends IRpcServiceReceiver> serviceReceiverClass) {
        this.serviceReceiverClass = serviceReceiverClass;
    }

    public long getIdleInterval() {
        return idleInterval;
    }

    public void setIdleInterval(long idleInterval) {
        this.idleInterval = idleInterval;
    }

    public int getIdleTimesClose() {
        return idleTimesClose;
    }

    public void setIdleTimesClose(int idleTimesClose) {
        this.idleTimesClose = idleTimesClose;
    }

    public String[] getRpcClientPackages() {
        return rpcClientPackages;
    }

    public void setRpcClientPackages(String[] rpcClientPackages) {
        this.rpcClientPackages = rpcClientPackages;
    }

    public long getReNodeInfoInterval() {
        return reNodeInfoInterval;
    }

    public void setReNodeInfoInterval(long reNodeInfoInterval) {
        this.reNodeInfoInterval = reNodeInfoInterval;
    }

	public Class<? extends ISerializer> getSerializeClass() {
		return serializeClass;
	}

	public void setSerializeClass(Class<? extends ISerializer> serializeClass) {
		this.serializeClass = serializeClass;
	}

	public int getSerializeDefSize() {
		return serializeDefSize;
	}

	public void setSerializeDefSize(int serializeDefSize) {
		this.serializeDefSize = serializeDefSize;
	}

	public int getSerializePoolSize() {
		return serializePoolSize;
	}

	public void setSerializePoolSize(int serializePoolSize) {
		this.serializePoolSize = serializePoolSize;
	}

	public String[] getInterceptorSenderChain() {
		return interceptorSenderChain;
	}

	public void setInterceptorSenderChain(String[] interceptorSenderChain) {
		this.interceptorSenderChain = interceptorSenderChain;
	}

	public String[] getInterceptorReceiverChain() {
		return interceptorReceiverChain;
	}

	public void setInterceptorReceiverChain(String[] interceptorReceiverChain) {
		this.interceptorReceiverChain = interceptorReceiverChain;
	}

	public boolean isSerializeInPlace() {
		return serializeInPlace;
	}

	public void setSerializeInPlace(boolean serializeInPlace) {
		this.serializeInPlace = serializeInPlace;
	}

}
